--------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  S:\Research\jmcss\Aggregation\Sims\Aggregation_Cases1234_19March_2022_1000.log
  log type:  text
 opened on:  19 Mar 2022, 12:49:47
r; t=0.03 12:49:47

. *This was created by Aggregation_Cases1234_19March_2022.do
. qui local rep = 10000
r; t=0.00 12:49:47

. qui local n=1000
r; t=0.00 12:49:47

. 
. foreach sigmax of numlist 0 0.20 0.40 { // 0 0.10 0.15
  2. foreach sigma  of numlist 0 0.40 0.56 { // 0 0.40 0.56
  3. di
  4. di "----------------------------------------------------------------------"
  5. if `sigma'==0&`sigmax'==0 di "CASE 1"
  6. if `sigma'!=0&`sigmax'==0 di "CASE 2"
  7. if `sigma'==0&`sigmax'!=0 di "CASE 3"
  8. if `sigma'!=0&`sigmax'!=0 di "CASE 4"
  9. di "----------------------------------------------------------------------"
 10. di
 11. foreach dgp of numlist 2 { // 1 2 Just use case 2 so that PPML is not optimal
 12. foreach t of numlist 60 { // 60 600
 13. 
. clear 
 14. set seed 24022022
 15. qui local obs=`n'*`t'
 16. qui local smpl=max(`obs',`rep')
 17. qui set obs `smpl'
 18. qui g obsr=_n
 19. qui local A=5 
 20. qui local B=2
 21. 
. qui gen ID=1+int((_n-1)/`t') if _n<=`obs'
 22. qui gen T=1+`t'*(((_n-1)/`t')-int((_n-1)/`t')) if _n<=`obs'
 23. qui xtset ID T
 24. 
. qui g bp=. if _n<=`rep'
 25. qui g bg=. if _n<=`rep'
 26. qui g wb0=. if _n<=`rep'
 27. 
. forvalues r = 1/`rep' {
 28. qui g beta=rnormal(0,`sigma') if _n<=`obs'
 29. qui bysort ID: egen betax=mean(beta) if _n<=`obs'
 30. qui replace beta=-1+betax*sqrt(`t')
 31. 
. qui g x=rnormal() if _n<=`obs'
 32. qui bysort ID: egen mx=mean(x) if _n<=`obs'
 33. qui replace x=mx*sqrt(`t')
 34. drop mx
 35. if `sigmax'!=0 qui replace x=rnormal(x,sqrt((1-`sigmax')*(x<0)+(1+`sigmax')*(x>0))) if _n<=`obs'
 36. qui bysort ID: egen mx=mean(x) if _n<=`obs'
 37. 
. if `dgp'<1.5 qui g double y=rchi2(rnbinomial(exp(-ln(`t')+beta*x+0.4)/(`A'-1),1/`A')) if _n<=`obs'
 38. if `dgp'>1.5 qui g double y=rchi2(rnbinomial(1/(`B'*`t'),1/(1+`B'*exp(beta*x+0.4))))  if _n<=`obs'
 39. qui replace y=0 if y==.&_n<=`obs' 
 40. qui bysort ID: egen my=sum(y) if _n<=`obs'
 41. sort obsr
 42. 
. qui g double yb0=y*beta if _n<=`obs'
 43. su yb0 if _n<=`obs', meanonly
 44. local mu0=r(mean)
 45. su y if _n<=`obs', meanonly
 46. qui replace wb0=`mu0'/r(mean) in `r'
 47. 
. qui glm my mx if T==1&_n<=`obs', irls robust link(log) family(poisson)
 48. qui replace bp= _b[mx] in `r'
 49. mat b=e(b)
 50. qui glm my mx if T==1&_n<=`obs', robust link(log) family(gamma) from(b)
 51. if e(converged)==1 qui replace bg= _b[mx] in `r'
 52. 
. drop x y* mx my* beta*  
 53. }
 54. di
 55. di "DGP = `dgp', S = " `sigma' ", Sx = " `sigmax' ", t = " `t' ", n = " `n' ", 
 56. su bp bg wb0 if _n<=`rep'
 57. di "----------------------------------------------------------------------"
 58. di "----------------------------------------------------------------------"
 59. di
 60. }
 61. }
 62. }
 63. }

----------------------------------------------------------------------
CASE 1
----------------------------------------------------------------------


DGP = 2, S = 0, Sx = 0, t = 60, n = 1000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -.9936993     .100963   -1.68797  -.6862197
          bg |     10,000   -1.010236    .0901593  -1.443009  -.6592385
         wb0 |     10,000          -1           0         -1         -1
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 2
----------------------------------------------------------------------


DGP = 2, S = .4, Sx = 0, t = 60, n = 1000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -1.142853     .222082  -3.637146  -.7090825
          bg |     10,000   -1.010961    .1005467   -1.50316  -.5762793
         wb0 |     10,000    -1.17263    .0881376  -2.110145  -.9991528
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 2
----------------------------------------------------------------------


DGP = 2, S = .56, Sx = 0, t = 60, n = 1000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -1.274893     .317958   -4.74638  -.6151975
          bg |     10,000   -1.009225    .1192543  -1.601371  -.3113062
         wb0 |     10,000    -1.35554    .1666996  -2.889963  -1.037667
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 3
----------------------------------------------------------------------


DGP = 2, S = 0, Sx = .2, t = 60, n = 1000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -.9400887    .1341104  -2.211728  -.5728602
          bg |     10,000    -.929603    .0916716  -1.352268   -.579447
         wb0 |     10,000          -1           0         -1         -1
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 4
----------------------------------------------------------------------


DGP = 2, S = .4, Sx = .2, t = 60, n = 1000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -1.127081    .2777811  -3.438583  -.2555392
          bg |     10,000   -1.039352    .1338574  -1.988022  -.2500738
         wb0 |     10,000   -1.299951    .1122382   -2.19271  -1.065027
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 4
----------------------------------------------------------------------


DGP = 2, S = .56, Sx = .2, t = 60, n = 1000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -1.202119    .3153676  -4.346926   .2395751
          bg |     10,000   -1.098822    .1657622  -1.995559   .2603186
         wb0 |     10,000    -1.54961    .1611919  -2.674045  -1.068296
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 3
----------------------------------------------------------------------


DGP = 2, S = 0, Sx = .4, t = 60, n = 1000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -.8832889    .1276774  -2.192717  -.2833467
          bg |     10,000    -.853171    .0899908  -1.237679  -.3752183
         wb0 |     10,000          -1           0         -1         -1
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 4
----------------------------------------------------------------------


DGP = 2, S = .4, Sx = .4, t = 60, n = 1000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -1.055374     .282036   -4.68187   .1113369
          bg |     10,000    -.933229     .130431  -1.732684   .1027668
         wb0 |     10,000   -1.279741    .1053308  -2.154781  -1.065791
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 4
----------------------------------------------------------------------


DGP = 2, S = .56, Sx = .4, t = 60, n = 1000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -1.151464     .336209  -4.257831    .422289
          bg |     10,000   -.9835079    .1646527  -1.753483   .1331719
         wb0 |     10,000   -1.532883    .1661433  -2.688712  -.4238895
----------------------------------------------------------------------
----------------------------------------------------------------------

r; t=52762.12 3:29:14

. capture log close
